package com.mk.admin.controller;

import com.mk.admin.log.WriteLog;
import com.mk.admin.model.ResultDto;
import com.mk.admin.model.query.AdminQuery;
import com.mk.admin.model.vo.AdminVo;
import com.mk.admin.service.AdminService;
import com.mk.admin.util.MD5;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/a/adm/admin")
@Api(tags = "账号设置(管理员和医生)")
public class AdminController {
    @Autowired
    private AdminService adminService;

    @PostMapping("/select")
    public ResultDto select(@RequestBody AdminQuery query) {
        return adminService.select(query);
    }

    @PostMapping("/add")
    public ResultDto add(@RequestBody AdminVo vo) {
        vo.setPassword(MD5.encoderByMd5(vo.getPassword()));
        return adminService.add(vo);
    }

    @PostMapping("/update")
    public ResultDto update(@RequestBody AdminVo vo) {
        vo.setPassword(MD5.encoderByMd5(vo.getPassword()));
        return adminService.update(vo);
    }

    @PostMapping("/delete")
    public ResultDto delete(@RequestBody AdminVo vo) {
        return adminService.delete(vo.getId());
    }

    @WriteLog("批量菜单删除")
    @PostMapping("/deleteBatchIds")
    public ResultDto deleteBatchIds(@RequestBody List<AdminVo> list) {
        return adminService.deleteBatchIds(list);
    }

    @PostMapping("/status")
    public ResultDto status(@RequestBody AdminVo vo) {
        return adminService.status(vo.getId());
    }

    @PostMapping("/selectDoctorInfo")
    @ApiOperation(value = "查询医生(医生，护士，药师)信息",notes = "只有管理员才需要返回值admin里面的参数adminId，username，nickName，email，headPath")
    public ResultDto selectDoctorInfo(@RequestBody AdminVo vo) {
        return adminService.selectDoctorInfo(vo);
    }

    @PostMapping("/selectRoleSysMenuByUsernameOrPhone")
    @ApiOperation(value = "查询角色对应的菜单信息", notes = "根据账号或者电话查询,账号可以为手机号")
    public ResultDto selectRoleSysMenuByUsernameOrPhone(@RequestBody AdminVo vo) {
        return adminService.selectRoleSysMenuByUsernameOrPhone(vo);
    }

}
